﻿<%@ Page Title="xbhinfo" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="jnxc.Web.xbhinfo.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">    
    <script src="../Script/sitedata.js"></script>
    <script src="../Script/city.js"></script>
    <script type="text/javascript">
        var provinceName;
        var cityName;
        var arrCity;
        var areaName;
        var arrArea;
        var provinceNames;
        var cityNames;
        var arrCitys;
        var areaNames;
        var arrAreas;
        $(function () {
            loadNameEdits();
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    var level = data[0].level - 1;
                    $('#level').val(level);
                    if (level == 2) {
                        provinceNames = data[0].province;
                        $('#uprovinces').combobox('setValue', data[0].province);
                        $("#dprovinces").hide();
                    }
                    if (level == 1) {
                        provinceNames = data[0].province;
                        $('#uprovinces').combobox('setValue', data[0].province);
                        cityNames = data[0].city;
                        $('#ucitys').combobox('setValue', data[0].city);
                        $("#dprovinces").hide();
                        $("#dcitys").hide();
                    }
                    if (level == 0) {
                        provinceNames = data[0].province;
                        $('#uprovinces').combobox('setValue', data[0].province);
                        cityNames = data[0].city;
                        $('#ucitys').combobox('setValue', data[0].city);
                        areaNames = data[0].county;
                        $('#ucountys').combobox('setValue', data[0].county);
                        $("#dprovinces").hide();
                        $("#dcitys").hide();
                        $("#dcountys").hide();
                    }
                }
            });

            InitGird();
            InitSearch();
        });
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '小班号列表', //表格标题
                url: 'GetXbh.ashx', //请求数据的页面
                sortName: 'xbhbh', //排序字段
                idField: 'xbhid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: $(parent.document).find("#mainPanle").height() - 35 > 0 ? $(parent.document).find("#mainPanle").height() - 35 : 500, //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,                
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
	                { title: '小班号', field: 'xbhbh', width: 150, sortable: true },
                    { title: '经度', field: 'jd', width: 150 },
                    { title: '纬度', field: 'wd', width: 150 },
                    { title: '海拨', field: 'hb', width: 150 },
                    { title: '面积', field: 'xbzone', width: 150 },
                    { title: '林分组成', field: 'lfzc', width: 120 },
                    { title: '省', field: 'uprovince', width: 120 },
                    { title: '市', field: 'ucity', width: 150 },
                    { title: '县', field: 'ucounty', width: 150 }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });


        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                //iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tt').datagrid('options').queryParams.search_type = name;
                    $('#tt').datagrid('options').queryParams.search_value = val;
                    $('#tt').datagrid('options').queryParams.uprovinces = $("#uprovinces").combobox("getValue");
                    $('#tt').datagrid('options').queryParams.ucitys = $("#ucitys").combobox("getValue");
                    $('#tt').datagrid('options').queryParams.ucountys = $("#ucountys").combobox("getValue");
                    $('#tt').datagrid('reload');
                },
                prompt: '请输入查询信息'
            });
        }
        function newUser() {
            //清空内容  
            $('#fm').form('clear');
            //加载工作人员的姓名和权限  
            loadNameEdit();
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    var level = data[0].level - 1;
                    $('#level').val(level);                    
                    if (level == 2) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        $("#dprovince").hide();                       
                    }
                    if (level == 1) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        cityName = data[0].city;
                        $('#ucity').combobox('setValue', data[0].city);
                        $("#dprovince").hide();
                        $("#dcity").hide();
                    }
                    if (level == 0) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        cityName = data[0].city;
                        $('#ucity').combobox('setValue', data[0].city);
                        areaName = data[0].county;
                        $('#ucounty').combobox('setValue', data[0].county);
                        $("#dprovince").hide();
                        $("#dcity").hide();
                        $("#dcounty").hide();
                    }
                }
            });           

            $('#dlg').dialog('open').dialog('setTitle', '添加小班号');
            document.getElementById("test").value = "add";
        }

        function getrowids(rows) {
            var ids = "";
            for (var i = 0; i < rows.length; i++)
                ids = ids + rows[i].xbhid + ",";
            if (ids != "")
                ids = ids.substr(0, ids.length - 1);
            return ids;

        }
        function editUser() {

            var row = $('#tt').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要修改的行！", "info");
            }

            //加载工作人员的姓名和权限  
            loadNameEdit();
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    var level = data[0].level - 1;
                    $('#level').val(level);                    
                    if (level == 2) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        $("#dprovince").hide();                       

                    }
                    if (level == 1) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        cityName = data[0].city;
                        $('#ucity').combobox('setValue', data[0].city);
                        $("#dprovince").hide();
                        $("#dcity").hide();
                    }
                    if (level == 0) {
                        provinceName = data[0].province;
                        $('#uprovince').combobox('setValue', data[0].province);
                        cityName = data[0].city;
                        $('#ucity').combobox('setValue', data[0].city);
                        areaName = data[0].county;
                        $('#ucounty').combobox('setValue', data[0].county);
                        $("#dprovince").hide();
                        $("#dcity").hide();
                        $("#dcounty").hide();
                    }
                }
            });
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '修改小班号');
                $('#xbhid').val(row.xbhid);
                document.getElementById("test").value = "modify";
                $('#fm').form('load', row);
            }
        }
        //添加        
        function saveUser() {
            var test = document.getElementById("test").value;
            var f = $('#fm');
            if (test == "add") {
                f.form('submit', {
                    url: "GetXbh.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                            $('#tt').datagrid('reload');
                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });

            } else {

                $('#fm').form('submit', {
                    url: "GetXbh.ashx?action=" + test,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        if (result.indexOf("T") == 0) {
                            $('#dlg').dialog('close');
                            $('#tt').datagrid('clearSelections');
                            $.messager.alert("提示", "恭喜您，信息修改成功", "info");
                            $('#tt').datagrid('reload');

                        }
                        else if ((result.indexOf("F") == 0)) {
                            $.messager.alert("提示", "添加失败，请重新操作！", "info");
                            return;
                        }
                        else if ((result.indexOf("L") == 0)) {
                            $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                            top.location = '/index.aspx';
                            return;
                        }
                    }
                });
            }
        }
        function removeUser() {
            var test = document.getElementById("test").value = "delete";
            var rows = $('#tt').datagrid('getSelections');
            if (rows == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (rows) {
                $.messager.confirm('提示', '你确定要删除这些信息吗？', function (r) {
                    if (r) {
                        var ids = getrowids(rows);
                        $('#fm').form('submit', {
                            url: 'GetXbh.ashx?xbhid=' + ids + "&action=" + test,
                            onSubmit: function () {                               
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#tt').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");                                   
                                    $('#tt').datagrid('reload');                                 

                                }
                                else if ((result.indexOf("F") == 0)) {
                                    $.messager.alert("提示", "删除失败，请重新操作！", "info");
                                    return;
                                }
                                else if ((result.indexOf("L") == 0)) {
                                    $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                                    top.location = '/index.aspx';
                                    return;
                                }
                            }

                        });
                    }
                })
            }
        }

    </script>
     <style type="text/css">
        .fitems {
        float:left;
        margin-right:10px;
        }
            .fitems label {
            width:40px;
            line-height:24px;
            }
    </style>  
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <div id="tab_toolbar" style="padding: 4px;">
        <table cellpadding="0" cellspacing="0" style="width: 100%">
            <tr>

                <td style="padding-left: 2px">


                    <a href="#" onclick="newUser();" id="a_add"
                        class="easyui-linkbutton" iconcls="icon-add">添加</a>    
                    <a href="javascript:void(0)" onclick="editUser() " class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>                
                    <a href="#" onclick="removeUser();return false;" id="a_del" class="easyui-linkbutton" iconcls="icon-cancel">删除</a>

                </td>
                <td style="text-align:left; padding-left: 15px">
                     <div class="fitems" id="dprovinces">
                <label>省：</label>
                <input id="uprovinces" name="uprovinces" class="easyui-combobox" data-options="width:'100'" />
            </div>
            <div class="fitems" id="dcitys">
                <label>市：</label>
                <input id="ucitys" name="ucitys" class="easyui-combobox" data-options="width:'100'"/>
            </div>
            <div class="fitems" id="dcountys">
                <label>县：</label>
                <input id="ucountys" name="ucountys" class="easyui-combobox" data-options="width:'100'" />
            </div>
                    <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width: 120px">
                        <div name="username">
                            林分组成
                        </div>
                        <div name="usernum">
                            小 班 号
                        </div>
                        
                    </div>
                </td>
            </tr>
        </table>

    </div>
    <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">       
        
        <form id="fm" method="post">

            <div class="fitem">
                <label>小班号：</label>
                <input id="xbhbh" name="xbhbh" class="easyui-validatebox" data-options="required:true" />
            </div>
            <div class="fitem">
                <label>经度：</label>
                <input id="jd" name="jd" class="easyui-validatebox" data-options="required:true" />
                <input name="Test" id="test" type="hidden" />
                <input name="xbhid" id="xbhid" type="hidden" />
                <input id="key" name="key" onkeydown="if(event.keyCode==13)reloadgrid()" type="hidden" />
                <input name="level" id="level" type="hidden" />
            </div>         
            <div class="fitem">
                <label>纬度：</label>
                <input id="wd" name="wd" class="easyui-validatebox" data-options="required:true" />
            </div>
            <div class="fitem">
                <label>海拨：</label>
                <input id="hb" name="hb" class="easyui-validatebox" data-options="required:true" />
            </div>
            <div class="fitem">
                <label>面积：</label>
                <input id="xbzone" name="xbzone" class="easyui-validatebox" data-options="required:true" />
            </div>
            <div class="fitem">
                <label>林分组成：</label>
                <input id="lfzc" name="lfzc" class="easyui-validatebox" data-options="required:true" />
            </div>            
            <div class="fitem" id="dprovince">
                <label>省：</label>
                <input id="uprovince" name="uprovince" class="easyui-combobox" />
            </div>
            <div class="fitem" id="dcity">
                <label>市：</label>
                <input id="ucity" name="ucity" class="easyui-combobox" />
            </div>
            <div class="fitem" id="dcounty">
                <label>县：</label>
                <input id="ucounty" name="ucounty" class="easyui-combobox" />
            </div>            
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="saveUser()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
    
</asp:Content>

